import QtQuick
import QtQuick.Controls
import QtQuick.Layouts

Item {
    id: mechineAngleBack
    width: 1760
    height: 300

    Rectangle{
        anchors.fill: parent
        border.width: 1
        color: "transparent"
    }


    property bool isOuterSwing: false

    Rectangle{
        id: leftAngleShow
        x: 100
        y: 50
        width: 200
        height: 200
        state: Cpp_PLC.M_390 ? "90度" : Cpp_PLC.M_394 ? "内摆45度" : "外摆45度"

        Rectangle{
            anchors.top: parent.top
            anchors.left: parent.left
            width: 40
            height: 40
            radius: 20
            border.width: 1
            color: Cpp_PLC.X14 ? "red" : "lightgray"
        }
        Rectangle{
            anchors.top: parent.top
            anchors.right: parent.right
            width: 40
            height: 40
            radius: 20
            border.width: 1
            color: Cpp_PLC.X12 ? "red" : "lightgray"
        }

        // Text{
        //     anchors.centerIn: parent
        //     font.pixelSize: 20
        //     text: parent.rotation
        // }

        states: [
            State {
                name: "内摆45度"
                PropertyChanges { leftAngleShow.rotation: 45 }
            },
            State {
                name: "90度"
                PropertyChanges { leftAngleShow.rotation: 0 }
            },
            State {
                name: "外摆45度"
                PropertyChanges { leftAngleShow.rotation: -45 }
            }

        ]
    }


    Rectangle{
        id: rightAngleShow
        x: 1400
        y: 50
        width: 200
        height: 200
        state: Cpp_PLC.M_391 ? "90度" : Cpp_PLC.M_394 ? "内摆45度" : "外摆45度"
        // Text{
        //     anchors.centerIn: parent
        //     font.pixelSize: 20
        //     text: parent.rotation
        // }

        Rectangle{
            anchors.top: parent.top
            anchors.left: parent.left
            width: 40
            height: 40
            radius: 20
            border.width: 1
            color: Cpp_PLC.X15 ? "red" : "lightgray"
        }
        Rectangle{
            anchors.top: parent.top
            anchors.right: parent.right
            width: 40
            height: 40
            radius: 20
            border.width: 1
            color: Cpp_PLC.X13 ? "red" : "lightgray"
        }

        states: [
            State {
                name: "内摆45度"
                PropertyChanges { rightAngleShow.rotation: -45 }
            },
            State {
                name: "90度"
                PropertyChanges { rightAngleShow.rotation: 0 }
            },
            State {
                name: "外摆45度"
                PropertyChanges { rightAngleShow.rotation: 45 }
            }
        ]
    }

    Column{
        anchors.top: mechineAngleBack.top
        anchors.topMargin: 20
        anchors.left: mechineAngleBack.left
        anchors.leftMargin: 500
        spacing: 20

        A_Button{
            buttonWidth: 120
            buttonHeight: 120
            contentText_Data: qsTr("45")
            contentText_Fontsize: 50
            isSelected: !Cpp_PLC.M_390

            onButtonPressed: {
                Cpp_PLC.write_into_PLC_Coils(13,true)
            }
            onButtonReleased: {
                Cpp_PLC.write_into_PLC_Coils(13,false)
            }
        }
        A_Button{
            buttonWidth: 120
            buttonHeight: 120
            contentText_Data: qsTr("90")
            contentText_Fontsize: 50
            isSelected: Cpp_PLC.M_390

            onButtonPressed: {
                Cpp_PLC.write_into_PLC_Coils(15,true)
            }
            onButtonReleased: {
                Cpp_PLC.write_into_PLC_Coils(15,false)
            }
        }

    }

    Column{
        anchors.top: mechineAngleBack.top
        anchors.topMargin: 20
        anchors.right: mechineAngleBack.right
        anchors.rightMargin: 500
        spacing: 20

        A_Button{
            buttonWidth: 120
            buttonHeight: 120
            contentText_Data: qsTr("45")
            contentText_Fontsize: 50
            isSelected: !Cpp_PLC.M_391

            onButtonPressed: {
                Cpp_PLC.write_into_PLC_Coils(14,true)
            }
            onButtonReleased: {
                Cpp_PLC.write_into_PLC_Coils(14,false)
            }
        }
        A_Button{
            buttonWidth: 120
            buttonHeight: 120
            contentText_Data: qsTr("90")
            contentText_Fontsize: 50
            isSelected: Cpp_PLC.M_391

            onButtonPressed: {
                Cpp_PLC.write_into_PLC_Coils(16,true)
            }
            onButtonReleased: {
                Cpp_PLC.write_into_PLC_Coils(16,false)
            }
        }

    }


    Column{
        anchors.top: mechineAngleBack.top
        anchors.topMargin: 10
        anchors.horizontalCenter: mechineAngleBack.horizontalCenter
        spacing: 20

        A_Button{
            buttonWidth: 300
            buttonHeight: 80
            contentText_Data: qsTr("左出锯")
            isSelected: Cpp_PLC.Mechine_Saws_Mode === "1"
            onButtonClicked: {
                Cpp_PLC.write_into_PLC_16_Hold(229,"1")
            }
        }
        A_Button{
            buttonWidth: 300
            buttonHeight: 80
            contentText_Data: qsTr("联动出锯")
            isSelected: Cpp_PLC.Mechine_Saws_Mode === "0"
            onButtonClicked: {
                Cpp_PLC.write_into_PLC_16_Hold(229,"0")
            }
        }
        A_Button{
            buttonWidth: 300
            buttonHeight: 80
            contentText_Data: qsTr("右出锯")
            isSelected: Cpp_PLC.Mechine_Saws_Mode === "2"
            onButtonClicked: {
                Cpp_PLC.write_into_PLC_16_Hold(229,"2")
            }
        }

    }


}
